///////////////////////////////////////////////////////////////////////////////
// KalmanTracker.h: KalmanTracker Class Declaration

#ifndef _UESTC_VHM_KALMAN_H_
#define _UESTC_VHM_KALMAN_H_

#include "opencv2/video/tracking.hpp"
#include "opencv2/highgui/highgui.hpp"

namespace ns_uestc_vhm {

#define StateType cv::Rect_<float>

// This class represents the internel state of individual tracked objects observed as bounding box.
class KalmanTracker {
public:
    KalmanTracker() {
        init_kf(StateType());
        m_time_since_update = 0;
        m_hits = 0;
        m_hit_streak = 0;
        m_age = 0;
        m_id = kf_count;
        m_classes = -1;
        m_prob = 0.0;
        // kf_count++;
    }
    KalmanTracker(StateType initRect, int classes, float prob) {
        init_kf(initRect);
        m_time_since_update = 0;
        m_hits = 0;
        m_hit_streak = 0;
        m_age = 0;
        m_id = kf_count;
        kf_count++;
        m_classes = classes;
        m_prob = prob;
    }

    ~KalmanTracker() {
        m_history.clear();
    }

    StateType predict();
    void update(StateType stateMat, int classes, float prob, cv::Mat feature);

    StateType get_state();
    StateType get_rect_xysr(float cx, float cy, float s, float r);

    static int kf_count;

    int m_time_since_update;
    int m_hits;
    int m_hit_streak;
    int m_age;
    int m_id;
    int m_classes;
    float m_prob;
    cv::Mat m_feature;

private:
    void init_kf(StateType stateMat);

    cv::KalmanFilter kf;
    cv::Mat measurement;

    std::vector<StateType> m_history;
};

} // ns_uestc_vhm

#endif // _UESTC_VHM_KALMAN_H_